<template>
	<view class="hot">
		<view class="hot-top">
			<view class="hot-left">推荐商品</view>
			<view class="hot-right">查看更多 ></view>
		</view>
		<uv-scroll-list :indicator="true">
			<view v-for="item in recommendList" :key="item.id" class="hot-img" @tap="toPage(item.id)">
				<uv-image :src="item.image[0] ? item.image[0] : '/static/images/default.png'" width="15vw" height="15vw"
					radius="2vw">
					<template v-slot:error>
						<uv-image src="/static/images/default.png" width="15vw" height="15vw" radius="2vw"></uv-image>
					</template>
				</uv-image>
				<view class="hot-text">{{ item.name }}</view>
			</view>
		</uv-scroll-list>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { productApi } from "@/api/index";
	const recommendList = ref();
	const getRecommendList = async () => {
		await productApi.getRecommenDproduct().then((res) => {
			recommendList.value = res.data;
		});
	};
	getRecommendList();

	const toPage = (id) => {
		uni.navigateTo({
			url: `/pages/productDetails/productDetails?id=${id}`
		});
	};
</script>

<style lang="scss">
	.hot {
		text-align: center;

		.hot-top {
			display: flex;
			justify-content: space-between;
			padding: 2vw;

			.hot-left {
				font-size: 28rpx;
				font-weight: 600;
			}

			.hot-right {
				font-size: 22rpx;
				color: #666;
			}
		}

		.hot-img {
			margin: 1vw 2vw;
		}

		.hot-text {
			font-size: 26rpx;
			max-width: 15vw;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}
</style>